package com.nju.mini_tiktok.bean;

import com.nju.mini_tiktok.API.VideoItem;
import com.nju.mini_tiktok.entity.ShortVideoInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 处理请求获取的数据，生成对应类型数据
 */
public class DataCreate {
    public static ArrayList<VideoBean> data;
    public static ArrayList<ShortVideoInfo> mList;

    public void initData(List<VideoItem> mDatas) {
        data = new ArrayList<>();
        mList = new ArrayList<>();
        for (int i = 0; i < mDatas.size(); i++) {
            VideoBean videoBean = new VideoBean();
            //设置视频信息
            videoBean.setUrl(mDatas.get(i).videoUrl);
            videoBean.setDescription(mDatas.get(i).description);
            videoBean.setCoverUrl(mDatas.get(i).coverUrl);
            //设置用户属性
            VideoBean.UserBean userBean = new VideoBean.UserBean();
            userBean.setAvatar(mDatas.get(i).avatarUrl);
            userBean.setNickName(mDatas.get(i).nickname);
            videoBean.setUserBean(userBean);
            //设置点赞数和是否点赞&关注
            videoBean.setLiked(false);
//            videoBean.setFocused(false);
            videoBean.setLikeCount(Integer.parseInt(mDatas.get(i).likeCount));
            //随机产生评论和分享数
//            int min = 4000;
//            int max = 8000;
//            Random random = new Random();
//            videoBean.setCommentCount(random.nextInt(max) % (max - min + 1) + min);
//            videoBean.setShareCount(random.nextInt(max) % (max - min + 1) + min);
            data.add(videoBean);
            System.out.println(mDatas.get(i).toString());


            ShortVideoInfo videoInfo = new ShortVideoInfo();
            videoInfo.setTextContent(mDatas.get(i).description);
            videoInfo.setAuthor(mDatas.get(i).nickname);
            videoInfo.setVideoCover(mDatas.get(i).coverUrl);
            videoInfo.setVideoUrl(mDatas.get(i).videoUrl);
            videoInfo.setAvatar(mDatas.get(i).avatarUrl);
            videoInfo.setLike(mDatas.get(i).likeCount);
            int min = 4000;
            int max = 8000;
            Random random = new Random();
            videoInfo.setNews(String.valueOf(random.nextInt(max) % (max - min + 1) + min));
            videoInfo.setZhuanfa(String.valueOf(random.nextInt(max) % (max - min + 1) + min));
            //videoInfo.setNews(mDatas.get(i).);
            mList.add(videoInfo);
        }
    }
}
